home *** CD-ROM | disk | FTP | other *** search
/ Aminet 35 / Aminet 35 (2000)(Schatztruhe)[!][Feb 2000].iso / Aminet / gfx / misc / gnuplot-src.lha / gnuplot-3.7.1src / gnuplot-3.7.1.lha / gnuplot-3.7.1 / eval.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-03  |  4.1 KB  |  140 lines

  1. #ifndef linti¥ýŸîSid = "$Id: eval.c,v 1.2 1998/11/03 12:52:12 lhecking Exp $";
  2. #endif
  3.  
  4. /* GNUPLOT - eval.c */
  5.  
  6. /*[
  7.  * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted,
  11.  * provided that the above copyright notice appear in all copies and
  12.  * that both that copyright notice and this permission notice appear
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the complete modified source code.  Modifications are to
  17.  * be distributed as patches to the released version.  Permission to
  18.  * distribute binaries produced by compiling modified sources is granted,
  19.  * provided you
  20.  *   1. distribute the corresponding source modifications from the
  21.  *    released version in the form of a patch file along with the binaries,
  22.  *   2. add special version identification to distinguish your version
  23.  *    in addition to the base release version number,
  24.  *   3. provide your name and address as the primary contact for the
  25.  *    support of your modified version, and
  26.  *   4. retain our contact information in regard to use of the base
  27.  *    software.
  28.  * Permission to distribute the released version of the source code along
  29.  * with corresponding source modifications in the form of a patch file is
  30.  * granted with same provisions 2 through 4 for binary distributions.
  31.  *
  32.  * This software is provided "as is" without express or implied warranty
  33.  * to the extent permitted by applicable law.
  34. ]*/
  35.  
  36.  
  37. #include "plot.h"
  38.  
  39.  
  40. struct udvt_entry *
  41.  add_udv(t_num)            /* find or add value and return pointer */
  42. int t_num;
  43. {
  44.     register struct udvt_entry **udv_ptr = &first_udv;
  45.  
  46.     /* check if it's already in the table... */
  47.  
  48.     while (*udv_ptr) {
  49.     if (equals(t_num, (*udv_ptr)->udv_name))
  50.         return (*udv_ptr);
  51.     udv_ptr = &((*udv_ptr)->next_udv);
  52.     }
  53.  
  54.     *udv_ptr = (struct udvt_entry *)
  55.     gp_alloc((unsigned long) sizeof(struct udvt_entry), "value");
  56.     (*udv_ptr)->next_udv = NULL;
  57.     copy_str((*udv_ptr)->udv_name, t_num, MAX_ID_LEN);
  58.     (*udv_ptr)->udv_value.type = INTGR;        /* not necessary, but safe! */
  59.     (*udv_ptr)->udv_undef = TRUE;
  60.     return (*udv_ptr);
  61. }
  62.  
  63.  
  64. struct udft_entry *
  65.  add_udf(t_num)            /* find or add function and return pointer */
  66. int t_num;            /* index to token[] */
  67. {
  68.     register struct udft_entry **udf_ptr = &first_udf;
  69.  
  70.     int i;
  71.     while (*udf_ptr) {
  72.     if (equals(t_num, (*udf_ptr)->udf_name))
  73.         return (*udf_ptr);
  74.     udf_ptr = &((*udf_ptr)->next_udf);
  75.     }
  76.  
  77.     /* get here => not found. udf_ptr points at first_udf or
  78.      * next_udf field of last udf
  79.      */
  80.  
  81.     if (standard(t_num))
  82.     int_warn("Warning : udf shadowed by built-in function of the same name", t_num);
  83.  
  84.     /* create and return a new udf slot */
  85.  
  86.     *udf_ptr = (struct udft_entry *)
  87.     gp_alloc((unsigned long) sizeof(struct udft_entry), "function");
  88.     (*udf_ptr)->next_udf = (struct udft_entry *) NULL;
  89.     (*udf_ptr)->definition = NULL;
  90.     (*udf_ptr)->at = NULL;
  91.     copy_str((*udf_ptr)->udf_name, t_num, MAX_ID_LEN);
  92.     for (i = 0; i < MAX_NUM_VAR; i++)
  93.     (void) Ginteger(&((*udf_ptr)->dummy_values[i]), 0);
  94.     return (*udf_ptr);
  95. }
  96.  
  97.  
  98. int standard(t_num)        /* return standard function index or 0 */
  99. int t_num;
  100. {
  101.     register int i;
  102.     for (i = (int) SF_START; ft[i].f_name != NULL; i++) {
  103.     if (equals(t_num, ft[i].f_name))
  104.         return (i);
  105.     }
  106.     return (0);
  107. }
  108.  
  109.  
  110.  
  111. void execute_at(at_ptr)
  112. struct at_type *at_ptr;
  113. {
  114.     register int i, index, count, offset;
  115.  
  116.     count = at_ptr->a_count;
  117.     for (i = 0; i < count;) {
  118.     index = (int) at_ptr->actions[i].index;
  119.     offset = (*ft[index].func) (&(at_ptr->actions[i].arg));
  120.     if (is_jump(index))
  121.         i += offset;
  122.     else
  123.         i++;
  124.     }
  125. }
  126.  
  127. /*
  128.  
  129.    'ft' is a table containing C functions within this program. 
  130.  
  131.    An 'action_table' contains pointers to these functions and arguments to be
  132.    passed to them. 
  133.  
  134.    at_ptr is a pointer to the action table which must be executed (evaluated)
  135.  
  136.    so the iterated line exectues the function indexed by the at_ptr and 
  137.    passes the address of the argument which is pointed to by the arg_ptr 
  138.  
  139.  */
  140.